/**
 * @ClassName Person
 * @Description 创建一个Person类，存储到ArrayList集合中，然后按年龄进行排序操作
 * @Author Li
 * @Date 2022/8/5 9:16
 * @ModifyDate 2022/8/5 9:16
 * @Version 1.0
 */
public class Person implements Comparable<Person> {
    private String name;
    private int age;

    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    // 用于等会直接打印Person对象
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    // 实现比较方法，不然不能直接使用sort(List<T> list)方法
    @Override
    public int compareTo(Person o) {
        return this.getAge() - o.getAge(); // 升序
    }
}
